package com.secondkill.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * Created by IBM on 2018/7/4.
 */
public class Md5Utils {

    private static final String clientSalt = "1a2b3c4d";
    private static String md5(String origin) {
        return DigestUtils.md5Hex(origin);
    }

    public static String inputPassToFormPass(String inputPass) {
        String passWithSalt = "" + clientSalt.charAt(0) + clientSalt.charAt(2) + inputPass + clientSalt.charAt(5) + clientSalt.charAt(4);
        return md5(passWithSalt);
    }

    public static String formPassToDbPass(String formPass, String serverSalt) {
        String passWithSalt = "" + serverSalt.charAt(0) + serverSalt.charAt(2) + formPass + serverSalt.charAt(5) + serverSalt.charAt(4);

        return md5(passWithSalt);
    }

    public static String inputPassToDbPass(String inputPass, String serverSalt) {
        String formPass = inputPassToFormPass(inputPass);
        return formPassToDbPass(formPass, serverSalt);
    }
    public static void main(String[] args) {

        String inputPass = "11111111111";
        System.out.println(inputPassToFormPass(inputPass));

        System.out.println(formPassToDbPass(inputPassToFormPass(inputPass), "1a3d4f5g"));
    }
}
